# Contributor: MehdiChinoune <mehdi.chinoune@hotmail.com>

_realname=lager
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.1.1
pkgrel=1
pkgdesc="C++ library for value-oriented design using the unidirectional data-flow architecture — Redux for C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: lager'
)
msys2_repository_url='https://github.com/arximboldi/lager/'
url='https://sinusoid.es/lager'
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/arximboldi/lager/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('9e4743c3fe2c95c1653c3fd088a2200108f09d758725697831852dc91d15d174')

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${_extra_config[@]}" \
      -Dlager_BUILD_TESTS=OFF \
      -Dlager_BUILD_FAILURE_TESTS=OFF \
      -Dlager_BUILD_EXAMPLES=OFF \
      -Dlager_BUILD_DEBUGGER_EXAMPLES=OFF \
      -Dlager_BUILD_DOCS=OFF \
      -Dlager_EMBED_RESOURCES_PATH=OFF \
      ../${_realname}-${pkgver}

  "${MINGW_PREFIX}"/bin/cmake.exe --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install .

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
